package com.lujieni.springbootrocketmq.service;

import com.alibaba.fastjson.JSON;
import com.lujieni.springbootrocketmq.dto.CsmApproveResultMessage;
import com.lujieni.springbootrocketmq.dto.OrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@RocketMQMessageListener(
        // 监听的 Topic
        topic = "csm-company-approve-topic",
        // 消费者组
        consumerGroup = "springboot-rocketmq",
        // 只消费 tag = a 的消息,tag的匹配是消费者客户端进行匹配的
        selectorExpression = "lujieni",
        // 消费失败重试次数 次数超过阈值发往死信队列 不包含首次消费
        maxReconsumeTimes = 1
)
@Slf4j
public class CsmConsumer implements RocketMQListener<CsmApproveResultMessage> {

    @Override
    public void onMessage(CsmApproveResultMessage OrderDTO) {
        System.out.println("prepare consume time:"+new Date() + "message:"+OrderDTO);
        int i = 5 / 0;
        // 业务处理逻辑
        log.info("CsmConsumer#onMessage:{}", JSON.toJSONString(OrderDTO));
    }

}